<?php

namespace app\api\controller\shop;

use app\admin\model\shop\Category;
use app\common\controller\Api;

/**
 * 商户接口
 */
class Shop extends Api
{

    protected $noNeedLogin = ['detail'];

    protected $noNeedRight = ['*'];

    //商户列表
    public function lists()
    {
        $params = input();
        try {
            $model = new \app\api\model\shop\Shop();

            $res = $model->lists($params,0);

        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('',$res);
    }

    public function lists2()
    {
        $params = input();
        try {
            $model = new \app\api\model\shop\Shop();

            $res = $model->lists($params,1);

        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('',$res);
    }

    //经营类目
    public function category()
    {
        $lists = Category::where(['status'=>'normal','pid'=>0])->order('weigh desc')->field('id,name')->select();
        $this->success('',$lists);
    }

    //商户详情
    public function detail()
    {
        $shop_id = input('shop_id',0);
        $lat = input('lat','');
        $lng = input('lng','');
        $model = new \app\api\model\shop\Shop();

        $res = $model->detail($shop_id,$lat,$lng);
        $this->success('',$res);
    }

    //商品详情
    public function goodsDetail()
    {
        $goods_id = input('goods_id',0);
        $lat = input('lat','');
        $lng = input('lng','');
        $model = new \app\api\model\shop\Shop();

        $res = $model->goodsDetail($goods_id,$lat,$lng);
        $this->success('',$res);
    }


    //海报
    public function poster()
    {
        $page = input('page','');

        $shop_id = input('shop_id',0);

        $app_type = input('app_type','weapp');

        $qrcode_param = input('qrcode_param','');//二维码

        if (empty($qrcode_param)) {
            $this->error('缺少二维码参数');
        }

        $qrcode_param = json_decode($qrcode_param, true);

        $qrcode_param[ 'suid' ] = $this->auth->id;

        $qrcode_param[ 'shop_id' ] = $shop_id;
        try {

            $model = new \app\api\model\shop\Shop();

            $res = $model->poster($page,$qrcode_param,$app_type);

        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('',$res);
    }


}